package com.ruoyi.central.config;

import com.ruoyi.common.config.RuoYiConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.thymeleaf.ThymeleafProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver;
import org.thymeleaf.templatemode.TemplateMode;

import java.nio.charset.StandardCharsets;

/**
 * @Classname ThymeleafConfigurator
 * @Author: sunluquan
 * @Date: 2022/7/1 14:56
 * @Description TODO
 */
@Configuration(proxyBeanMethods = false)
public class ThymeleafConfigurator {


    @Bean
    public SpringResourceTemplateResolver resourceTemplateResolverOfCustom(){

        SpringResourceTemplateResolver templateResolver = new SpringResourceTemplateResolver();
        templateResolver.setPrefix("file:"+ RuoYiConfig.getProfile()+"/templates");
        templateResolver.setSuffix(ThymeleafProperties.DEFAULT_SUFFIX);
        templateResolver.setTemplateMode(TemplateMode.HTML);
        templateResolver.setCharacterEncoding(StandardCharsets.UTF_8.name());
        templateResolver.setOrder(Ordered.LOWEST_PRECEDENCE);
        templateResolver.setCheckExistence(true);

        return templateResolver;
    }
}
